USE [DSRSystem_Temp]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spGetFinalizedCompanies]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spGetFinalizedCompanies]
GO


CREATE PROCEDURE [dbo].[spGetFinalizedCompanies]
@ChangedSince datetime,
@Skip  int,
@Take int 
AS
BEGIN
	SELECT CompanyId, CompanyName, CapitalIQID, AnalystCommentary, LastFinalUpdate FROM FinalizedCompanies 
	WHERE LastFinalUpdate > @ChangedSince
	OR LastCentralizedResearchUpdate > @ChangedSince
	OR LastCorporateDataUpdate > @ChangedSince
	ORDER BY CompanyId
	OFFSET  @Skip ROWS 
	FETCH NEXT @Take ROWS ONLY 

END
GO


